package com.example.blackbox.Activity;


import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;

import com.example.blackbox.Broadcast.MineBroadcast;
import com.example.blackbox.Fragment.CommunityFragment;
import com.example.blackbox.Fragment.GameFragment;
import com.example.blackbox.Fragment.IndexFragment;
import com.example.blackbox.Fragment.MineFragment;
import com.example.blackbox.R;

import org.w3c.dom.Text;


public class MainActivity  extends FragmentActivity {

    FragmentManager fm;
    Fragment indexFragment,gameFragment,communityFragment,mineFragment;
    LinearLayout mBtIndex,mBtGame,mBtMine;
    TextView mTvIndex,mTvGame,mTvCommunity,mTvMine;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    public void init(){
        fm=getSupportFragmentManager();
        indexFragment=new IndexFragment();
        gameFragment=new GameFragment();
        communityFragment=new CommunityFragment();
        mineFragment=new MineFragment();

        mBtIndex=(LinearLayout)findViewById(R.id.index);
        mBtGame=(LinearLayout)findViewById(R.id.game);
        mBtMine=(LinearLayout)findViewById(R.id.mine);

        mTvIndex=(TextView)findViewById(R.id.main_tv_index);
        mTvGame=(TextView)findViewById(R.id.main_tv_game);
        mTvMine=(TextView)findViewById(R.id.main_tv_mine);

        fm.beginTransaction().replace(R.id.fragment_container,indexFragment).commit();

        mBtIndex.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fm.beginTransaction().replace(R.id.fragment_container, indexFragment).commit();
                mTvIndex.setTextColor(Color.rgb(33,150,243));
                mTvGame.setTextColor(Color.rgb(0,0,0));
                mTvMine.setTextColor(Color.rgb(0,0,0));

            }
        });
        mBtGame.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fm.beginTransaction().replace(R.id.fragment_container, gameFragment).commit();
                mTvIndex.setTextColor(Color.rgb(0,0,0));
                mTvGame.setTextColor(Color.rgb(33,150,243));
                mTvMine.setTextColor(Color.rgb(0,0,0));
            }
        });

        mBtMine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fm.beginTransaction().replace(R.id.fragment_container, mineFragment).commit();
                mTvIndex.setTextColor(Color.rgb(0,0,0));
                mTvGame.setTextColor(Color.rgb(0,0,0));
                mTvMine.setTextColor(Color.rgb(33,150,243));
            }
        });

        IntentFilter filter=new IntentFilter();
        filter.addAction("EXIT_INFO_ACTION");
        MineBroadcast myBroadCastReceiver=new MineBroadcast(MainActivity.this);
        registerReceiver(myBroadCastReceiver,filter);
    }


}
